import 'package:flutter/material.dart';
import 'package:navigator_demo/navigator1pointzero/common_page.dart';

class OthersDemo extends StatelessWidget {
  const OthersDemo({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('demo_page.dart'),
      ),
      body: ListView(
        children: [
          ListTile(
            title: Text('push(route `A`)'),
            onTap: () {
              final route = MaterialPageRoute(
                  builder: (context) => CommonPage(
                        settings: RouteSettings(name: 'A'),
                      ));
              Navigator.of(context).push(route);
            },
          ),
          ListTile(
            title: Text('pushAndRemoveUntil(route `A`, `/`)'),
            onTap: () {
              final route = MaterialPageRoute(
                  builder: (context) => CommonPage(
                        settings: RouteSettings(name: 'A'),
                      ));
              Navigator.of(context)
                  .pushAndRemoveUntil(route, ModalRoute.withName('/'));
            },
          ),
          ListTile(
            title: Text('pushNamed(`A`)'),
            onTap: () {
              Navigator.of(context).pushNamed(
                'A',
              );
            },
          ),
          ListTile(
            title: Text('pushNamedAndRemoveUntil(`A`, `/`)'),
            onTap: () {
              Navigator.of(context)
                  .pushNamedAndRemoveUntil('A', ModalRoute.withName('/'));
            },
          ),
          ListTile(
            title: Text('pushReplacement(route `A`)'),
            onTap: () {
              final route = MaterialPageRoute(
                  builder: (context) => CommonPage(
                        settings: RouteSettings(name: 'A'),
                      ));
              Navigator.of(context).pushReplacement(route);
            },
          ),
          ListTile(
            title: Text('pushReplacementNamed(`A`)'),
            onTap: () {
              Navigator.of(context).pushReplacementNamed('A');
            },
          ),
          ListTile(
            title: Text('popAndPushNamed(`A`, `/`)'),
            onTap: () {
              Navigator.of(context).popAndPushNamed('A');
            },
          ),
          ListTile(
            title: Text('popUntil(`/`)'),
            onTap: () {
              Navigator.of(context).popUntil(ModalRoute.withName('/'));
            },
          ),
          ListTile(
            title: Text('pop'),
            onTap: () {
              Navigator.of(context).pop();
            },
          ),
          ListTile(
            title: Text('canPop: ${Navigator.of(context).canPop()}'),
            onTap: () {
              if (Navigator.of(context).canPop()) {
                Navigator.of(context).pop();
              }
            },
          ),
          ListTile(
              title: Text('maybePop'),
              onTap: () async {
                Navigator.of(context).maybePop();
              }),
        ],
      ),
    );
  }
}
